package concurrent.thread_create;

import java.util.List;
import java.util.concurrent.*;

public class UseExecutorService {
    public static void main(String[] args) throws ExecutionException, InterruptedException {
        ExecutorService poolA = Executors.newFixedThreadPool(2);
        //execute只能传入runnable接口。
        poolA.execute(()->{
            System.out.println("4A......");
        });
        poolA.shutdown();
        // 又或者自定义线程池
        ThreadPoolExecutor poolB = new ThreadPoolExecutor(2, 3, 0,
                TimeUnit.SECONDS, new LinkedBlockingQueue<Runnable>(3),
                Executors.defaultThreadFactory(), new ThreadPoolExecutor.AbortPolicy());
        //这里submit可以传入runnable接口或者call接口的匿名内部类。
        Future<String> submit = poolB.submit(() -> {
            return "4B......";
        });
        System.out.println(submit.get());
        //使用完后一定要关闭池子
        poolB.shutdown();
    }
}
